package net.gz01.wallet.common;

import java.text.DecimalFormat;
import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

public class PageRespon {

	private int code;
	private String msg;
	private int count;
	private List<?> data;
	private Record totalInfo;

	public PageRespon() {
	}

	public PageRespon(Page<?> pr) {
		this.code = 0;
		this.count = pr.getTotalRow();
		this.data = pr.getList();
	}

	public Record getTotalInfo() {
		return totalInfo;
	}

	public void setTotalInfo(Record totalInfo) {
		if (totalInfo.getLong("amount") == null) {
			totalInfo.set("amount", 0);
		}
		if (totalInfo.getLong("fee") == null) {
			totalInfo.set("fee", 0);
		}
		this.totalInfo = totalInfo;
	}
	
	public String getSumAmount() {
		return totalInfo == null ? "" : new DecimalFormat("#,##0.00").format(totalInfo.getLong("amount") / 100.0);
	}

	public String getSumFee() {
		return totalInfo == null ? "" : new DecimalFormat("#,##0.00").format(totalInfo.getLong("fee") / 100.0);
	}

	public int getSumCount() {
		return totalInfo == null ? 0 : totalInfo.getInt("count");
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List<?> getData() {
		return data;
	}

	public void setData(List<?> data) {
		this.data = data;
	}

}
